﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Diagnostics;
using System.Threading;

namespace iCloudPortal
{
    /// <summary>
    /// Interaction logic for ToolbarWindow.xaml
    /// </summary>
    public partial class ToolbarWindow : Window
    {
        public MainWindow MainWindow { get; private set; }

        protected int EventBreaker;

        public ToolbarWindow(MainWindow mainWindow)
        {
            InitializeComponent();
            MainWindow = mainWindow;

            EventBreaker = 0;
            MainWindow.Activated += (o, e) =>
                {
                    try
                    {
                        Interlocked.Add(ref EventBreaker, 1);
                        this.Show();
                        Interlocked.Add(ref EventBreaker, -1);
                    }
                    catch { }
                };

            MainWindow.Deactivated += (o, e) =>
                {
                    if (EventBreaker != 0)
                    {
                        return;
                    }

                    this.Hide();
                };

            this.MouseEnter += (o, e) => Interlocked.Add(ref EventBreaker, 1);
            this.MouseLeave += (o, e) => Interlocked.Add(ref EventBreaker, -1);
        }

        private void ExitButton_Click(object sender, RoutedEventArgs e)
        {
            if (MessageBox.Show(MainWindow,"Are you sure you wants to quit Windy's iCloud Portal?", MainWindow.Title, MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No) == MessageBoxResult.Yes)
                App.Current.Shutdown();
        }

        private void RefreshButton_Click(object sender, RoutedEventArgs e)
        {
            MainWindow.RefreshBrowser();

        }

        private void HomeButton_Click(object sender, RoutedEventArgs e)
        {
            MainWindow.BrowseHome();
        }

        //private void ExitButton_Click(object sender, RoutedEventArgs e)
        //{
        //    throw new NotImplementedException();

        //private void ExitButton_Click(object sender, RoutedEventArgs e)
        //{
        //    throw new NotImplementedException();

        //private void ExitButton_Click(object sender, RoutedEventArgs e)
        //{
        //    throw new NotImplementedException();
        //}

        //}
        //}

    }

}
